package com.gxuwz.zlc.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 将Date类型的Sun Dec 12 13:12:12 CST 2021格式转为2021-12-12 13:12:12(String类型)并赋值给Str
 */
public class DateToString {

    public static String dateToString(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        Date d = null;
        try {
            d = sdf.parse(date.toString());  //date.toString()将Date类型转换成字符串
        } catch (ParseException e) {
        }
        String formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);
        return formatDate;
    }

}
